//
//  MainViewController.m
//  Campus
//
//  Created by ios on 2017/2/20.
//  Copyright © 2017年 吕金状. All rights reserved.
//

#import "MainViewController.h"

@interface MainViewController ()<UITabBarControllerDelegate>

@end

@implementation MainViewController

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    
    _home = [HomeViewController new];
    _Discover = [[DiscoverViewController alloc] init];
    _Video = [VideoViewController new];
    //我的
    _my = [[MineViewController alloc] init];
    
    
    [self addchildViewVc:_home withImagName:@"shouyehui" andTitle:@"首页" andSeletdImage:@"shouye"];
    [self addchildViewVc:_Video withImagName:@"fenleihui" andTitle:@"视频" andSeletdImage:@"fenlei"];
    [self addchildViewVc:_Discover withImagName:@"kefuhui" andTitle:@"发现" andSeletdImage:@"kefu"];
  //  [self addchildViewVc:_shop withImagName:@"gouwuchehui" andTitle:@"购物车" andSeletdImage:@"gouwuche11"];
    [self addchildViewVc:_my withImagName:@"wohui" andTitle:@"我的" andSeletdImage:@"wo"];
    
  
    
    

    
        
    
}

//添加子控制器方法
- (void)addchildViewVc:(UIViewController *)vc withImagName:(NSString *)imgName andTitle:(NSString *)titile andSeletdImage:(NSString *)seletdImage{
   
    //设置标题
    vc.title = titile;
    //设置选中状态item背景颜色
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:getColor(navColor),NSFontAttributeName:DEF_FontSize_14} forState:UIControlStateSelected];
    //设置图片
    UIImage * iconImage = [UIImage imageNamed:imgName];
    iconImage = [iconImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.image = [UIImage imageNamed:imgName];
    //设置选中图片
    UIImage * iconImageSel = [UIImage imageNamed:seletdImage];
    iconImageSel = [iconImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = iconImageSel;
    
 
    //添加子控制器
    UINavigationController *navVc = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:navVc];
}

#pragma mark - UITabBarControllerDelegate

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
//    if ([self.viewControllers firstObject] == viewController) {
//         [[NSNotificationCenter defaultCenter] postNotificationName:@"tanchujianpan" object:nil userInfo:nil];
//    }
}


@end
